package com.wanke.dao;

import com.wanke.domian.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface UserRepository extends JpaRepository<User, Integer> {

    //自定义查询
    List<User> findAllByUsername(String str);

    List<User> findAllByUsernameAndPassword(String str,String str2);

    //模糊查询
    List<User> findAllByUsernameLike(String str);

    //自定义sql语句查询
    @Query("select  u from User  u")
    List<User> findAllUser();

    //自定义查询想要的 列
    @Query("select u.username from User u")
    List<String> findAllByZidingyiUsername();


    @Transactional
    @Modifying
    @Query("update User u set u.username=?1,u.password = ?2 where u.id=?3")
    Integer updatezidingyiUsername(String username,String password,int id);

}
